package com.xuchaotong.concurrent;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchExample {
    private static CountDownLatch countDownLatch = new CountDownLatch(5);
    public static void main(String[] args) {
        Thread t = null;
        for (int i = 0;i < 5;i++){
            t = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("我是线程：" + Thread.currentThread().getName());
                    countDownLatch.countDown();
                }
            },"thread->"+i);

            t.start();
        }

        try {
            countDownLatch.await();

            System.out.println("线程都执行完了！");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
